package com.project.controller;

import com.project.bean.ProductBean;
import com.project.bean.ShoppingCarBean;
import com.project.bean.UserBean;
import com.project.service.IShoppingCarService;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("shop")
public class ShopController {
    @Autowired
    private IShoppingCarService service;
    @RequestMapping("showShopList")
    public List<ShoppingCarBean> showShopList(HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        return service.findById(user.getId());
    }

    @RequestMapping("buy")
    public String buy(Integer productId,HttpServletRequest req){
        UserBean user = (UserBean) req.getSession().getAttribute("loginUser");
        service.addCar(productId,user.getId());
        return "ok";
    }

    @RequestMapping("del")
    public String del(Integer shopId){
        service.removeCar(shopId);
        return "ok";
    }
    @RequestMapping("updateNum")
    public String update(Integer shopId,Integer num){
        service.update(shopId, num);
        return "ok";
    }
}
